// xc/components/picker/dateime.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    active:1,
    show:false,
    currentDate: new Date().getTime(),
    maxDate: new Date().getTime(),
    yearcolumns:[],
    currentYear: new Date().getFullYear(),
  },
  ready(){
    // this.init()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onClose(e){
       this.setData({
        show:false
       })
    },
    init(year,month){
      var update={show:true}
      update['show']=true;
      if(month==-1){
        update['active']=0;
       update['currentYear']=year;   

      }else{
       var oldTime = (new Date(year+'/'+month+"/01 00:00:00")).getTime();
       update['currentDate']=oldTime;   
      }
  
      var nowyear=new Date().getFullYear()
      var yearcolumns=[];
      for(var i=0;i<10;i++){
        yearcolumns.push(nowyear - i)
      }
      update['yearcolumns']=yearcolumns;

      this.setData(update)
      
    },
    ontimecomfirm(event) {
   
      var time = new Date(event.detail);
      var y = time.getFullYear();
      var m = time.getMonth()+1;
      var detail={};
      detail['year']= y;
      detail['month']= m;
      this.triggerEvent('choose', detail)
      this.setData({
        show:false
      })
    },
    onConfirm(e){
      console.log(e)
      var detail={};
      detail['year']= e.detail.value;
      detail['month']= -1;
      this.triggerEvent('choose', detail)
      this.setData({
        show:false
      })
    }
  }
})
